package com.boarsoft.dao.sharding.bean;

import org.springframework.util.Assert;

public class ShardingParam {
	protected String policy = ""; // 不允许为NULL
	protected Object key;
	protected Object session;
	protected Object transaction;

	@Override
	public boolean equals(Object o) {
		if (o == null) {
			return false;
		}
		if (!(o instanceof ShardingParam)) {
			return false;
		}
		ShardingParam t = (ShardingParam) o;
		if (policy.equals(t.getPolicy())) {
			if (key == null) {
				return t.getKey() == null;
			}
			return key.equals(t.getKey());
		}
		return false;
	}

	public ShardingParam(String policy, Object key) {
		Assert.notNull(policy, "DaoSharding policy could not be null");
		this.policy = policy;
		this.key = key;
	}

	public String getPolicy() {
		return policy;
	}

	public void setPolicy(String policy) {
		Assert.notNull(policy, "DaoSharding policy could not be null");
		this.policy = policy;
	}

	public Object getKey() {
		return key;
	}

	public void setKey(Object key) {
		this.key = key;
	}

	public Object getSession() {
		return session;
	}

	public void setSession(Object session) {
		this.session = session;
	}

	public Object getTransaction() {
		return transaction;
	}

	public void setTransaction(Object transaction) {
		this.transaction = transaction;
	}
}
